package com.kaifamiao.entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.kaifamiao.enums.Gender;
import com.kaifamiao.json.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.relational.core.mapping.Table;

import java.time.LocalDate;

@Table("t_users")
public class User {

    @Id
    private Integer id;
    private String account; // 账号
    private String email; // 邮箱
    private String tel; // 手机号
    private String password; // 密码
    private String salt; // 盐值
    private String nickname; // 昵称
    private Gender gender; // 性别
    private LocalDate birthdate; // 出生日期
    private boolean married; // 是否已婚
    private boolean admin; // 是否是管理员

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTel() {
        return tel;
    }

    public void setTel(String tel) {
        this.tel = tel;
    }

    @JsonSerialize(using = NullSerializer.class)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @JsonSerialize(using = NullSerializer.class)
    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    @JsonSerialize(using = GenderSerializer.class)
    public Gender getGender() {
        return gender;
    }

    @JsonDeserialize(using = GenderDeserializer.class)
    public void setGender(Gender gender) {
        this.gender = gender;
    }

    @JsonSerialize(using = BirthdateSerializer.class)
    public LocalDate getBirthdate() {
        return birthdate;
    }

    @JsonDeserialize(using = BirthdateDeserializer.class)
    public void setBirthdate(LocalDate birthdate) {
        this.birthdate = birthdate;
    }

    @JsonSerialize(using = BooleanSerializer.class)
    public boolean isMarried() {
        return married;
    }

    @JsonDeserialize(using = BooleanDeserializer.class)
    public void setMarried(boolean married) {
        this.married = married;
    }

    @JsonSerialize(using = BooleanSerializer.class)
    public boolean isAdmin() {
        return admin;
    }

    @JsonDeserialize(using = BooleanDeserializer.class)
    public void setAdmin(boolean admin) {
        this.admin = admin;
    }

}
